home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / tex / lgrind.zoo / docstrip.tex < prev    next >
Text File  |  1992-09-28  |  15KB  |  544 lines

  1. % $Id: docstrip.tex,v 1.1 91/09/08 03:53:12 gvr Exp $
  2. %
  3. %% This is file `docstrip.tex' generated
  4. %% on <1991/2/1> with the docstrip utility (v1.1l test). 
  5. %% 
  6. %% The original source file was `docstrip.doc'.
  7. %% Included modules: `stats'.
  8. %% 
  9. %% IMPORTANT NOTICE:
  10. %% You are not allowed to distribute this file.
  11. %% For distribution of the original source see 
  12. %% the copyright notice in the file `docstrip.doc'. 
  13. %% 
  14. \def\filename{docstrip}
  15. \def\fileversion{v1.1l test}
  16. \def\filedate{90/12/10}
  17. \def\docdate {90/06/15}
  18.  
  19. %% \CheckSum{835}
  20. %% \CharacterTable
  21. %%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
  22. %%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
  23. %%   Digits        \0\1\2\3\4\5\6\7\8\9
  24. %%   Exclamation   \!     Double quote  \"     Hash (number) \#
  25. %%   Dollar        \$     Percent       \%     Ampersand     \&
  26. %%   Acute accent  \'     Left paren    \(     Right paren   \)
  27. %%   Asterisk      \*     Plus          \+     Comma         \,
  28. %%   Minus         \-     Point         \.     Solidus       \/
  29. %%   Colon         \:     Semicolon     \;     Less than     \<
  30. %%   Equals        \=     Greater than  \>     Question mark \?
  31. %%   Commercial at \@     Left bracket  \[     Backslash     \\
  32. %%   Right bracket \]     Circumflex    \^     Underscore    \_
  33. %%   Grave accent  \`     Left brace    \{     Vertical bar  \|
  34. %%   Right brace   \}     Tilde         \~}
  35. %%
  36. \nofiles
  37.  
  38. \makeatletter
  39.  
  40.  
  41. %% correcting a LaTeX bug first...
  42. \def\@xtypein[#1]#2{\typeout{#2}\read\sixt@@n to#1\ifx #1\@defpar
  43.   \def#1{}\else
  44.    \@iden{\expandafter\@strip\expandafter
  45.    #1#1\@gobble\@gobble} \@gobble\fi\@typein}
  46.  
  47. \typeout{LaTeX utility: `docstrip'
  48.    \fileversion\space <\filedate> (FMi)}
  49. \typeout{English documentation
  50.  \@spaces\@spaces\space\space <\docdate> (FMi)}
  51. \typeout{}
  52. \typeout{**********************************************************}
  53. \typeout{* This program converts documented macro-files into fast *}
  54. \typeout{* loadable files by stripping of (nearly) all comments!
  55.                                                             \space*}
  56. \typeout{**********************************************************}
  57. \typeout{}
  58.  
  59. \def\test@batchfile{%
  60.   \ifx\undefined\batchfile
  61.     \let\batchfile\default@batchfile
  62.     \@okaytrue \else \@okayfalse \fi
  63.   \openin\batch@stream \batchfile\relax
  64.   \ifeof\batch@stream
  65.     \if@okay \else
  66.       \typeout{*************************************************}
  67.       \typeout{* Could not find your \string\batchfile=\batchfile}
  68.       \typeout{* Try to continue without it}
  69.       \typeout{*************************************************}
  70.     \fi
  71.   \else
  72.     \if@okay
  73.       \typeout{*************************************************}
  74.       \typeout{* Batch file docstrip.cmd found. Use it ? (y/n) *}
  75.       \typein[\answer]
  76.               {*************************************************}
  77.       \def\@tempa{y}%
  78.     \else \let\answer\@tempa \fi
  79.     \ifx\@tempa\answer \process@batchfile \fi
  80.   \fi}
  81.  
  82. \def\ask@questions{%
  83.    \typeout{}
  84.    \typeout{***************************************************}
  85.    \typeout{* First type the extension of your input file(s): *}
  86.    \typein[\infileext]
  87.            {***************************************************}
  88.    \typeout{}
  89.    \typeout{**************************************************}
  90.    \typeout{* Now type the extension of your output file(s): *}
  91.    \typein[\outfileext]
  92.            {**************************************************}
  93.    \typeout{}
  94.    \typeout{**************************************************}
  95.    \typeout{* Now give the name(s) of module(s) to include: \space *}
  96.    \typein[\includelist]
  97.            {**************************************************}
  98.    \typeout{}
  99.    \typeout{**************************************************}
  100.    \typeout{* Finally give the list of input file(s) without *}
  101.    \typeout{* extension separated by commas if necessary:\@spaces*}
  102.    \typein[\filelist]
  103.            {**************************************************}}
  104.  
  105. \newif\if@okay
  106. \newread\@infile
  107. \newread\@outfile
  108.  
  109. \def^^L{ }
  110.  
  111. \def\set@filenames{%
  112.     \edef\in@filename{\main@filename.\infileext}%
  113.     \edef\out@filename{\main@filename.\outfileext}}
  114.  
  115. \def\check@filenames{%
  116.   \ifx\infileext\outfilext
  117.     \typeout{}
  118.     \typeout{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  119.     \typeout{! Not possible to read from and write to the same file !}
  120.     \typeout{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  121.     \@okayfalse
  122.   \else
  123.     \@okaytrue
  124.     \immediate\openin\@infile \in@filename \relax
  125.     \ifeof \@infile
  126.       \@okayfalse
  127.       \typeout{}
  128.       \typeout{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  129.       \typeout{! Input file `\in@filename' not found !}
  130.       \typeout{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  131.     \else
  132.       \check@outfile
  133.     \fi
  134.     \immediate\closein\@infile
  135.   \fi}
  136.  
  137. \def\check@outfile{%
  138.    \immediate\openin\@outfile \out@filename \relax
  139.    \ifeof \@outfile \@okaytrue
  140.    \else
  141.      \@okayfalse
  142.      \typeout{}
  143.      \typeout{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  144.      \typeout{! Output file `\out@filename' already exists.}
  145.      \typeout{! Do you want to overwrite it? (yes/no)}
  146.      \typein[\answer]{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  147.      \def\@tempa{yes}%
  148.      \ifx\answer\@tempa \@okaytrue \fi
  149.     \fi
  150.     \immediate\closein\@outfile}
  151.  
  152. \def\write@postamble{%
  153.     \owrite{\string\endinput}%
  154.     \owrite{\double@percent}%
  155.     \owrite{\double@percent End of file `\out@filename'.}%
  156.     \immediate\closeout\@outfile}
  157.  
  158.   \newcount\numberof@files
  159.   \newcount\meta@comment
  160.   \newcount\normal@comment
  161.   \newcount\code@line
  162.   \newcount\processed@line
  163.   \newcount\summeta@comment
  164.   \newcount\sumnormal@comment
  165.   \newcount\sumcode@line
  166.   \newcount\sumprocessed@line
  167.  
  168. \def\process@line{%
  169.   \advance\processed@line\@ne
  170.     \futurelet\next\process@@line}
  171.  
  172. \begingroup
  173. \catcode`\*=12
  174. \lccode`\*=`\%
  175. \lowercase{%
  176. \gdef\double@percent{** }
  177. \gdef\percent@{*}
  178. \gdef\process@@line{%
  179.     \if*\next
  180.       \expandafter\check@second
  181.     \else
  182.   \advance\code@line\@ne
  183.   \endlast@module
  184.            \expandafter\put@line
  185.     \fi}
  186. \gdef\check@@second{%
  187.   \if*\next
  188.  \advance\meta@comment\@ne
  189.  \endlast@module
  190.           \let\next\put@line
  191.    \else
  192.     \if<\next
  193.       \let\next\check@module
  194.     \else
  195.  \advance\normal@comment\@ne
  196.  \endlast@module
  197.       \let\next\remove@line
  198.     \fi
  199.   \fi
  200.   \next}
  201. }
  202.  
  203. \endgroup
  204.  
  205. \gdef\check@second#1{\futurelet\next\check@@second}
  206.  
  207. \def\check@module<{\futurelet\next\check@@module}
  208.  
  209. \def\check@@module{%
  210.     \if+\next
  211.      \let\next\plus@module
  212.     \else
  213.       \if-\next
  214.         \let\next\minus@module
  215.       \else
  216.         \if*\next
  217.           \let\next\star@module
  218.         \else
  219.           \if/\next
  220.             \let\next\slash@module
  221.          \else
  222.             \advance\normal@comment\@ne
  223.             \endlast@module
  224.             \let\next\remove@line
  225.           \fi
  226.         \fi
  227.       \fi
  228.     \fi
  229.     \next}
  230.  
  231. \def\module@included#1#2{%
  232.    \ifin@line@module
  233.      \def\@tempa{#1#2}%
  234.      \ifx\@tempa\curr@module \else
  235.      \maybe@message{>}\in@line@modulefalse \module@included#1{#2}\fi
  236.    \else
  237.      \in@line@moduletrue
  238.      \def\curr@module{#1#2}%
  239.      \maybe@message{<#1#2}%
  240.       \inclcurr@modulefalse
  241.       \@for\@tempa:=#2\do
  242.       {\edef\@tempb{\noexpand\in@{\@tempa,}{\includelist,}}%
  243.       \@tempb \ifin@ \inclcurr@moduletrue \fi}%
  244.     \fi
  245. }
  246.  
  247. \def\endlast@module{%
  248.    \ifin@line@module
  249.      \maybe@message{>}\in@line@modulefalse \fi}
  250.  
  251.  \newif\ifin@line@module
  252. \newif\ifinclcurr@module
  253.  
  254. \def\plus@module+#1>{%
  255.   \module@included+{#1}%
  256.   \ifinclcurr@module
  257.  \advance\code@line\@ne
  258.           \expandafter\put@module
  259.   \else
  260.  \advance\normal@comment\@ne
  261.           \expandafter\remove@line
  262.   \fi}
  263.  
  264. \newif\ifoutput@block \output@blocktrue
  265. \newif\ifin@block
  266.  
  267. \def\star@module*#1>{%
  268.  \ifin@block
  269.   \errmessage{Already in block <\block@type>}%
  270.  \else
  271.   \in@blocktrue
  272.   \def\block@type{*#1}%
  273.   \module@included*{#1}%
  274.   \in@line@modulefalse
  275.   \ifinclcurr@module
  276.     \output@blocktrue
  277.   \else
  278.     \output@blockfalse
  279.   \fi
  280.  \fi
  281.  \advance\normal@comment\@ne
  282.  \remove@line
  283. }
  284.  
  285. \def\slash@module/#1>{%
  286.  \ifin@block
  287.   \in@blockfalse
  288.   \output@blocktrue
  289.  \maybe@message{\perc